let goods_js = {

    /**
     * 当前JS需要的所有的后台接口
     */
    url: {
        /**
         * 学生首页面路径
         * @returns {string}
         */
        ngx_kafka_log_path: function(){
            return "http://192.168.0.113/log";
        },
    },

    /**
     * 商品页面初始化
     */
    init: function (){
        console.log('商品列表页面进行初始化');
    },

    /**
     * 查看商品详情,并且生成订单
     * 如果没有登录弹出登录窗口，登录之后，下单
     * @param goodsId   商品ID
     */
    goodsDetail: function (goodsId){
        console.log('点击商品进行下单');
        let user_id = $.cookie("lgn_name");
        if (!user_id){
            $('#exampleModal').modal('show');
        } else {
            let param = {};
            param['goodsId'] = goodsId;
            goods_js.sendLog("order", param);
            window.location.href = ctx + 'rabbitmq/goods/' + goodsId + '/detail';
        }
    },

    /**
     * 绑定查看详情，下单按钮
     */
    login: function (){
        console.log('用户登录');
        let phoneNumber = $('#phone_number').val();
        console.log(phoneNumber);
        goods_js.add_to_cookie(phoneNumber);
    },

    /**
     * 添加手机号到cookie，模拟登录
     * @param phoneNumber
     */
    add_to_cookie: function (phoneNumber){
        $.cookie("lgn_name", phoneNumber, {expires:7, path:'/'})
        $('#exampleModal').modal('hide');
    },

    /**
     * 向nginx日志系统发送用户操作信息
     * @param action 行为代码
     */
    sendLog: function (action, param){
        console.log('发送收集日志消息');
        $.ajax({
            url: goods_js.url.ngx_kafka_log_path(),
            type: "POST",
            async: false,
            data: goods_js.combine(action, param),
            dataType: "JSON",
            success:function (data) {
                console.log(data);
            },
            error:function () {
                console.log('发送收集日志失败');
            }
        })
    },

    /**
     * 封装发送数据
     * @param act   行为代码
     * @param param   行为参数
     * @returns {{"user_id":"13273910594","act_time": "2021-03-12 00:00:00","action":"order"}}
     */
    combine: function (act, param) {
        let user_id = $.cookie("lgn_name");
        let act_time = new Date().getTime();
        let action = act;

        param["user_id"] = user_id;
        param["act_time"] = act_time;
        param["action"] = action;

        return param;
    }
}